import os
import sys

script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
sys.path.append(script_dir)
from typing import List
from pygame import Surface, transform
from pygame.sprite import AbstractGroup
from baseClass.other import *
from baseClass.plant import *
from baseClass.zombie import *
from baseClass.plantingArea import *
from baseClass.base import *
from baseClass.scene import *
from threading import Thread


class lawn(PlantingArea):
    """植被草坪"""

    def __init__(
        self,
        plantGroup: AbstractGroup,
        x: int,
        y: int,
        width: int,
        height: int,
    ) -> None:
        super().__init__(
            plantGroup,
            {
                AERIAL_PLANTS,
                AERIAL_SHELL_PLANTS,
                TERRESTRIAL_PLANTS,
                TERRESTRIAL_SHELL_PLANTS,
            },
            x,
            y,
            width,
            height,
        )

    def addPlant(self, plant: Plant) -> bool:
        """种植

        :para plant: 种植的植物
        """
        if plant.Type in self.plantingTarget and plant.Type not in self.plants:
            plant.rect.x = self.x
            h = plant.rect.height // 8
            if plant.Type == AERIAL_PLANTS:
                plant.rect.centery = self.rect.top - h
            elif plant.Type == AERIAL_SHELL_PLANTS:
                plant.rect.centery = self.rect.top + h
            elif plant.Type == TERRESTRIAL_PLANTS or plant.Type == AQUATIC_PLANTS:
                plant.rect.centery = self.rect.bottom - h
            elif (
                plant.Type == TERRESTRIAL_SHELL_PLANTS
                or plant.Type == AQUATIC_SHELL_PLANTS
            ):
                plant.rect.centery = self.rect.bottom + h
            self.plants.add(plant.Type)
            self.plantGroup.add(plant)
            return True
        return False


class DawnDay:
    """白天场景"""

    def __init__(
        self,
    ) -> None:
        super().__init__()
        self.backgroundImg = pygame.image.load("./PVZ素材/场景/白天.jpg")
        self.groundImgRect = self.backgroundImg.get_rect()

    def draw(self, screen: Surface):
        screenRect = screen.get_rect()
        scale_factor = min(
            screenRect.width / self.groundImgRect.width,
            screenRect.height / self.groundImgRect.height,
        )
        self.backgroundImg = transform.scale(
            self.backgroundImg,
            (
                int(self.groundImgRect.width * scale_factor),
                int(self.groundImgRect.height * scale_factor),
            ),
        )
        self.groundImgRect = self.backgroundImg.get_rect()
        self.groundImgRect.center = screenRect.center
        screen.blit(self.backgroundImg, self.groundImgRect)

    def dynamicEven(self, *args, **kwargs):
        """动态事件"""
        pass
